package com.ysd.lis.service.lab.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.lab.LabRptdetailStaining;
import com.ysd.lis.mapper.lab.LabRptdetailStainingMapper;
import com.ysd.lis.service.lab.LabRptdetailStainingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author cfz
 * @since 2024-03-26
 */
@Service
public class LabRptdetailStainingServiceImpl extends ServiceImpl<LabRptdetailStainingMapper, LabRptdetailStaining> implements LabRptdetailStainingService {
    @Autowired
    LabRptdetailStainingMapper labRptdetailStainingMapper;

    @Override
    public Result findLabRptdetailStainingList(LabRptdetailStaining labRptdetailStaining) {
        MPJLambdaWrapper<LabRptdetailStaining> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.eq(LabRptdetailStaining::getDelFlag, 0);
        List<LabRptdetailStaining> list = labRptdetailStainingMapper.selectList(queryWrapper);
        return Result.succ(1, "请求成功", list);
    }

    @Override
    public List<LabRptdetailStaining> findLabRptdetailStainingArray(LabRptdetailStaining labRptdetailStaining) {
        MPJLambdaWrapper<LabRptdetailStaining> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.eq(LabRptdetailStaining::getDelFlag, 0);
        queryWrapper.eq(StringUtils.isNotBlank(labRptdetailStaining.getRptMainCode()), LabRptdetailStaining::getRptMainCode, labRptdetailStaining.getRptMainCode());
        queryWrapper.eq(StringUtils.isNotBlank(labRptdetailStaining.getBacStainingResultId()), LabRptdetailStaining::getBacStainingResultId, labRptdetailStaining.getBacStainingResultId());
        return labRptdetailStainingMapper.selectList(queryWrapper);
    }

    @Override
    public Result addLabRptdetailStaining(LabRptdetailStaining labRptdetailStaining) {
        int i = labRptdetailStainingMapper.insert(labRptdetailStaining);
        if (i > 0) {
            return Result.succ(1, "新增成功", labRptdetailStaining);
        }
        return Result.fail("新增失败");
    }

    @Override
    public Result deleteLabRptdetailStaining(LabRptdetailStaining labRptdetailStaining) {
        labRptdetailStaining.setDelFlag(1);
        int i = labRptdetailStainingMapper.updateById(labRptdetailStaining);
        if (i > 0) {
            return Result.succ(1, "删除成功", labRptdetailStaining);
        }
        return Result.fail("删除失败");
    }

    @Override
    public Result updateLabRptdetailStaining(LabRptdetailStaining labRptdetailStaining) {
        int i = labRptdetailStainingMapper.updateById(labRptdetailStaining);
        if (i > 0) {
            return Result.succ(1, "更新成功", labRptdetailStaining);
        }
        return Result.fail("更新失败");
    }
}
